package cn.tedu.charging.device.service.impl;

import cn.tedu.charging.device.dao.repository.StationRepository;
import cn.tedu.charging.device.pojo.po.StationPO;
import cn.tedu.charging.device.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: goodman
 * @Date: 2025/4/24 22:00
 */
@Slf4j
@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
    private StationRepository stationRepository;


    @Override
    public List<StationInfoVO> nearStation(Double longitude, Double latitude, Double radius) {
        List<StationPO> stationPOS = stationRepository.nearStations(longitude, latitude, radius);
        //定义返回结果 List<StationInfoVO> 列表
        List<StationInfoVO> stationInfoVOS = new ArrayList<>();
        //循环附近的场站PO列表
        for (StationPO stationPO : stationPOS) {
            StationInfoVO stationInfoVO = new StationInfoVO();
            //stationInfoVO.setId(stationPO.getId());
            //stationInfoVO.setStationName(stationPO.getStationName());
            //如果要拷贝的字段太多，可以使用spring提供的工具类 BeanUtils.copyProperties
            BeanUtils.copyProperties(stationPO, stationInfoVO);
            stationInfoVOS.add(stationInfoVO);
        }
        return stationInfoVOS;
    }
}
